//
//  SJUploadBar.m
//  WSL
//
//  Created by CJ on 2017/11/17.
//  Copyright © 2017年 sanjuetech. All rights reserved.
//

#import "SJUploadBar.h"

@interface SJUploadBar ()

@property (strong, nonatomic) UIScrollView *containView;
@property (strong, nonatomic) UIButton *buttonItem_0;
@property (strong, nonatomic) UIButton *buttonItem_1;
@property (strong, nonatomic) UIButton *buttonItem_2;
@property (strong, nonatomic) UIButton *buttonItem_3;
@property (strong, nonatomic) UIButton *buttonItem_4;
@property (strong, nonatomic) UIButton *buttonItem_5;

@end

@implementation SJUploadBar

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    [self addSubview:self.containView];
    self.containView.sd_layout
    .centerYEqualToView(self)
    .centerXEqualToView(self)
    .heightIs(SJLayoutFrame(60))
    .widthIs(SJScreenW - SJLayoutFrame(39));
    
    [self.containView addSubview:self.buttonItem_0];
    self.buttonItem_0.sd_layout
    .leftSpaceToView(self.containView, SJLayoutFrame(0))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(60))
    .widthIs(SJLayoutFrame(60));
    
    [self.containView addSubview:self.buttonItem_1];
    self.buttonItem_1.sd_layout
    .leftSpaceToView(self.buttonItem_0, SJLayoutFrame(32))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(60))
    .widthIs(SJLayoutFrame(60));
    
    
    [self.containView addSubview:self.buttonItem_2];
    self.buttonItem_2.sd_layout
    .leftSpaceToView(self.buttonItem_1, SJLayoutFrame(32))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(60))
    .widthIs(SJLayoutFrame(60));
    
    [self.containView addSubview:self.buttonItem_3];
    self.buttonItem_3.sd_layout
    .leftSpaceToView(self.buttonItem_2, SJLayoutFrame(32))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(60))
    .widthIs(SJLayoutFrame(60));
    
//    [self.containView addSubview:self.buttonItem_4];
//    self.buttonItem_4.sd_layout
//    .leftSpaceToView(self.buttonItem_3, SJLayoutFrame(32))
//    .centerYEqualToView(self.containView)
//    .heightIs(SJLayoutFrame(60))
//    .widthIs(SJLayoutFrame(60));
//
//    [self.containView addSubview:self.buttonItem_5];
//    self.buttonItem_5.sd_layout
//    .leftSpaceToView(self.buttonItem_4, SJLayoutFrame(32))
//    .centerYEqualToView(self.containView)
//    .heightIs(SJLayoutFrame(60))
//    .widthIs(SJLayoutFrame(60));
    
    [self.containView setupAutoContentSizeWithRightView:self.buttonItem_3 rightMargin:0];
    
    UIImageView *leftImageView = [UIImageView new];
    leftImageView.image = [UIImage imageNamed:@"sicang_icon_arrow_left"];
    
    [self addSubview:leftImageView];
    leftImageView.sd_layout
    .rightSpaceToView(self.containView, SJLayoutFrame(6))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(8.5))
    .widthIs(SJLayoutFrame(7.5));
    
    
    UIImageView *rightImageView = [UIImageView new];
    rightImageView.image = [UIImage imageNamed:@"sicang_icon_arrow_right"];
    
    [self addSubview:rightImageView];
    rightImageView.sd_layout
    .leftSpaceToView(self.containView, SJLayoutFrame(6))
    .centerYEqualToView(self.containView)
    .heightIs(SJLayoutFrame(8.5))
    .widthIs(SJLayoutFrame(7.5));
}

//- (void)setHasPictures:(BOOL)hasPictures {
//    
//    _hasPictures = hasPictures;
//    
//    if (hasPictures) {
//        self.buttonItem_3.enabled = YES;
//    } else {
//        self.buttonItem_3.enabled = NO;
//    }
//}


#pragma mark -- getter

- (UIScrollView *)containView {
    
    if (!_containView) {
        
        _containView = [UIScrollView new];
        _containView.showsVerticalScrollIndicator = NO;
        _containView.showsHorizontalScrollIndicator = NO;
        
    }
    return _containView;
}

- (void)selectedItem:(UIButton *)button {
    
    NSInteger index = button.tag;
    
    if ([self.delegate respondsToSelector:@selector(uploadBar:didSelectItemAtIndex:)]) {
    
        [(id<SJUploadBarDelegate>)self.delegate uploadBar:self didSelectItemAtIndex:index];
    }
}

- (UIButton *)buttonItem_0{
    
    if (!_buttonItem_0) {
        
        _buttonItem_0 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_0 setImage:[UIImage imageNamed:@"sicang_bt_entry_nor"] forState:UIControlStateNormal];
        [_buttonItem_0 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_0.tag = 0;
        
    }
    return _buttonItem_0;
}

- (UIButton *)buttonItem_1{
    
    if (!_buttonItem_1) {
        
        _buttonItem_1 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_1 setImage:[UIImage imageNamed:@"sicang_bt_text_nor"] forState:UIControlStateNormal];
        [_buttonItem_1 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_1.tag = 1;
        
    }
    return _buttonItem_1;
}

- (UIButton *)buttonItem_2{
    
    if (!_buttonItem_2) {
        
        _buttonItem_2 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_2 setImage:[UIImage imageNamed:@"sicang_bt_pic_nor"] forState:UIControlStateNormal];
        [_buttonItem_2 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_2.tag = 2;
        
    }
    return _buttonItem_2;
}

//- (UIButton *)buttonItem_3{
//
//    if (!_buttonItem_3) {
//
//        _buttonItem_3 = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_buttonItem_3 setImage:[UIImage imageNamed:@"sicang_bt_picplus_nor"] forState:UIControlStateNormal];
//        [_buttonItem_3 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
//        _buttonItem_3.tag = 3;
//
//    }
//    return _buttonItem_3;
//}

- (UIButton *)buttonItem_3{
    
    if (!_buttonItem_3) {
        
        _buttonItem_3 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_3 setImage:[UIImage imageNamed:@"sicang_bt_cutboard_nor"] forState:UIControlStateNormal];
        [_buttonItem_3 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_3.tag = 3;
        
    }
    return _buttonItem_3;
}

- (UIButton *)buttonItem_4{
    
    if (!_buttonItem_4) {
        
        _buttonItem_4 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_4 setImage:[UIImage imageNamed:@"sicang_bt_cutboard_nor"] forState:UIControlStateNormal];
        [_buttonItem_4 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_4.tag = 4;
        
    }
    return _buttonItem_4;
}

- (UIButton *)buttonItem_5{
    
    if (!_buttonItem_5) {
        
        _buttonItem_5 = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buttonItem_5 setImage:[UIImage imageNamed:@"sicang_bt_audio_nor"] forState:UIControlStateNormal];
        [_buttonItem_5 addTarget:self action:@selector(selectedItem:) forControlEvents:UIControlEventTouchUpInside];
        _buttonItem_5.tag = 5;
        
    }
    return _buttonItem_5;
}

@end
